#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

// 读取源文件内容
const typesContent = fs.readFileSync(path.join(__dirname, '../src/types.ts'), 'utf8');
const presetsContent = fs.readFileSync(path.join(__dirname, '../src/presets.ts'), 'utf8');

// 生成类型声明文件内容
const dtsContent = `import type { DefineComponent } from 'vue'

// 从 types.ts 导出的类型
${typesContent.replace(/export /g, 'export declare ').replace(/import.*from.*['"].*['"];?\n/g, '')}

// PhoneUI 组件类型
export declare const PhoneUI: DefineComponent<PhoneUIProps>

// 从 presets.ts 导出的预设数据
export declare const phonePresets: PhonePresets

// Vue 插件安装函数
export declare function install(app: any): void

// 默认导出
declare const _default: {
  install: typeof install
}

export default _default
`;

// 写入类型声明文件
const distDir = path.join(__dirname, '../dist');
if (!fs.existsSync(distDir)) {
  fs.mkdirSync(distDir, { recursive: true });
}

fs.writeFileSync(path.join(distDir, 'index.d.ts'), dtsContent);
console.log('✓ TypeScript declaration file generated successfully!');
